import express, { Express, Request, Response , Application } from 'express';
import dotenv from 'dotenv';
import cors from 'cors';
import swaggerUi from 'swagger-ui-express';
import { swaggerSpec } from './src/swagger';
import { chatRoutes } from './src/chatRoute';
import { recordRoute } from './src/recordRoute';
//For env File 
dotenv.config();

const app: Application = express();
const port = process.env.PORT || 8000;

app.use(cors());
app.use(express.json());

// Swagger 文档
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));

// 根路径重定向到 API 文档
app.get('/', (req: Request, res: Response) => {
  res.redirect('/api-docs');
});

// API 路由
app.use('/chat', chatRoutes);
app.use('/records', recordRoute);

app.listen(port, () => {
  console.log(`Server is Fire at https://localhost:${port}`);
  console.log(`Swagger Docs: http://localhost:${port}/api-docs`);
});